/**
 * 
 */
package com.aem.sticky.button;

import org.newdawn.slick.Image;
import org.newdawn.slick.Sound;
import org.newdawn.slick.geom.Shape;


/**
 * Button with two sets of faces.
 * 
 * @author abacs
 *
 */
public class TwoStateButton extends SimpleButton {

	
	protected Image _upA;
	protected Image _upB;
	protected Image _downA;
	protected Image _downB;
	
	
	// -------------------------------------------------------------------------
	
	public TwoStateButton(
			Shape shape,
			Image imgUpA,
			Image imgDownA,
			Image imgUpB,
			Image imgDownB,
			Sound sound
	) {
		super(shape, imgUpA, imgDownA, sound);
		this._upA = imgUpA;
		this._downA = imgDownA;
		this._upB = imgUpB;
		this._downB = imgDownB;
	}

	@Override
	public void onClick(Button clicked, float mx, float my) {
		this.switchState();
		
		super.onClick(clicked, mx, my);
	}
	
	public void switchState() {
		if(this.current == this._upA || this.current == this._downA)
			this.setStateB();
		else
			this.setStateB();
	}
	
	
	public void setStateA() {
		this.up = this._upA;
		this.down = this._downA;
		
		if(this.current == this._upB)
			this.current = this._upA;
		if(this.current == this._downB)
			this.current = this._downA;
	}
	
	
	public void setStateB() {
		this.up = this._upB;
		this.down = this._downB;
		
		if(this.current == this._upA)
			this.current = this._upB;
		if(this.current == this._downA)
			this.current = this._downB;
	}
	
	
	/**
	 * 
	 * @param x corner position x
	 * @param y corner position y
	 */
	public void moveTo(float x, float y) {
		this.shape.setX(x);
		this.shape.setY(y);
	}

	/**
	 * 
	 */
	public void hide() {
		this.moveTo(-this.shape.getWidth(), -this.shape.getHeight());
	}
}
